package org.jwos.plugin.file.domain;

import java.io.Serializable;

public class FileInfo extends MappableBean implements Serializable {

	private String id;

	private String name = "";
	
	private String path = "";

	private boolean folder = false;

	private long size = 0;

	private String type = "unknown";

	private String icon = "unknown";

	private String dateCreated = "";

	private String dateModified = "";

	private int folderType = FolderType.FileFolder;

	private String description = "";
	
	private boolean shared = false;
	
	private boolean published = false;
	
	private String tags = "";
	
	private long fileCount;
	
	private long folderCount;

	public FileInfo() {
	}	
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isFolder() {
		return folder;
	}

	public void setFolder(boolean folder) {
		this.folder = folder;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}
	
	public String getFormatSize() {
		return FolderType.formatSize(size);
	}

	public String getType() {
		if(this.folder) {
			this.setType("Folder");
		} else {
			if(this.name!=null) {
				int index = this.name.lastIndexOf(".");
				if(index>0) {
					String ext = this.name.substring(index + 1);
					this.setType(ext.toUpperCase()+" File");
				}
			} else {
				this.setType("Unknown");
			}
		}		
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getIcon() {
		if(this.folder) {
			if(this.getFolderType()==FolderType.MyNetworkUser) {
				this.setIcon("network-user");
			} else if(this.getFolderType()==FolderType.PublishedFiles) {
				this.setIcon("published-files");
			} else if(this.getFolderType()==FolderType.PublishedFolders) {
				this.setIcon("published-folders");
			} else if(this.shared) {
				this.setIcon("folder-shared");
			} else {
				this.setIcon("folder");
			}
		} else {
			if(this.name!=null) {
				int index = this.name.lastIndexOf(".");
				if(index>0) {
					String ext = this.name.substring(index + 1);
					this.setIcon(FolderType.getIconByFileExt(ext));
				}
			} else {
				this.setIcon("unknown");
			}						
		}
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(String dateCreated) {
		this.dateCreated = dateCreated;
	}

	public String getDateModified() {
		return dateModified;
	}

	public void setDateModified(String dateModified) {
		this.dateModified = dateModified;
	}

	public int getFolderType() {
		return folderType;
	}

	public void setFolderType(int folderType) {
		this.folderType = folderType;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getStatus() {
		if(this.isShared() && this.isPublished()) {
			return FolderType.Status_SharedPublished;
		} else if(this.isShared()) {
			return FolderType.Status_Shared;
		} else if(this.isPublished()) {
			return FolderType.Status_Published;
		} else {
			return FolderType.Status_None;
		}
	}

	public boolean isShared() {
		return shared;
	}

	public void setShared(boolean shared) {
		this.shared = shared;
	}

	public boolean isPublished() {
		return published;
	}

	public void setPublished(boolean published) {
		this.published = published;
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public long getFileCount() {
		return fileCount;
	}

	public void setFileCount(long fileCount) {
		this.fileCount = fileCount;
	}

	public long getFolderCount() {
		return folderCount;
	}

	public void setFolderCount(long folderCount) {
		this.folderCount = folderCount;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
}
